home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume19 / cnews2 / part06 < prev    next >
Encoding:
Internet Message Format  |  1989-06-29  |  45.6 KB

  1. Subject:  v19i083:  Cnews production release, Part06/19
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: utzoo!henry
  7. Posting-number: Volume 19, Issue 83
  8. Archive-name: cnews2/part06
  9.  
  10. : ---CUT HERE---
  11. echo 'contrib/nntpmail/mailing_lists/distribute':
  12. sed 's/^X//' >'contrib/nntpmail/mailing_lists/distribute' <<'!'
  13. X#!/bin/sh
  14. X#
  15. X# $Header: distribute,v 1.18 88/09/18 22:26:23 lamy Exp $
  16. X#
  17. X# Distribute stdin (presumed to be a digest or direct-mail article from
  18. X# a mailing list) according to the following flags
  19. X#
  20. X# -n newsgroup        post article to specified newsgroup.
  21. X# -a file        append to the file specified.
  22. X# -m people        remail to people, people may be a filename
  23. X#            in which case the contents will be assumed
  24. X#            to be a list of recipients, one to a line.
  25. X#            note that in the case of a file all recipients
  26. X#            will appear on the headers, and therefore
  27. X#            an alias is best used for large lists.
  28. X# -d directory        store into a file named by volume and
  29. X#            issue under "directory".  Useful for digests.
  30. X# -am name        shorthand for '-a name -m /local/share/mail/lists/name'
  31. X# -dm name        shorthand for '-d name -m /local/share/mail/lists/name'
  32. X#
  33. X# Notes:
  34. X# - When using -a or -m alone, a full path is required, which does differ
  35. X#   with what -am and -dm expect (the name of the mailing list only).
  36. X# - If invoked from sendmail, all arguments will be lowercase only!
  37. X#
  38. X# Rayan Zachariassen - rayan@ai.toronto.edu
  39. X# touch-ups by Jean-Francois Lamy - lamy@ai.toronto.edu
  40. X
  41. X#exec 2>&1
  42. X#set -x
  43. Xumask 022
  44. X
  45. XUSAGE='distribute [-n newsgroup] [-a archivefile] [-d archivedir] [-m mailto]'
  46. X
  47. X# could be the same site, though not necessarily
  48. Xthissite=`domainname`.toronto.edu
  49. Xnewsserver=jarvis.csri.toronto.edu
  50. X
  51. X# we keep the archives under our anonymous FTP directory so other people
  52. X# can get at them.
  53. Xarchdir=/local/ftp
  54. Xcd $archdir
  55. X
  56. X# this person receives bounces and such like.  Make it an alias as it
  57. X# will appear on the sender: line of messages.
  58. Xadmin=list-admin
  59. X
  60. XPEOPLE=/local/share/mail/lists
  61. XLOG=/var/log/distribute
  62. X
  63. XMail=/usr/ucb/Mail
  64. Xsendmail=/usr/lib/sendmail
  65. Xcat=/bin/cat
  66. Xrm=/bin/rm
  67. X# This program should be suid daemon, so that sensitive files can be
  68. X# protected.
  69. Xblankcat=/local/lib/mail/bin/appendfile
  70. X
  71. X#
  72. X# Parse arguments
  73. X#
  74. XARTICLE=/tmp/dist$$
  75. Xnewsgroup=""
  76. Xfile=""
  77. Xdirectory=""
  78. Xmailto=""
  79. Xcase $# in
  80. X0|1)    echo Usage: $USAGE
  81. X    exit 1 ;;
  82. Xesac
  83. Xstate=x
  84. Xfor i in $@
  85. Xdo
  86. X    case "$i" in
  87. X    -*)    state=$i ;;
  88. X    *)    case $state in
  89. X        -n)    newsgroup="$i"
  90. X            distribution="`expr $newsgroup : '\([a-z]*\)\.*'`"
  91. X            ;;
  92. X        -n*)    newsgroup="$i"
  93. X            distribution="`expr $state : '-n\(.*\)'`"
  94. X            ;;
  95. X        -a)    file="$i" ;;
  96. X        -d)    directory="$i" ;;
  97. X        -m)    mailto="$i" ;;
  98. X        -am)    file="$i"
  99. X            mailto="$PEOPLE/$i" ;;
  100. X        -dm)    directory="$i"
  101. X            mailto="$PEOPLE/$i" ;;
  102. X        x)    echo Usage: $USAGE
  103. X            exit 2 ;;
  104. X        esac
  105. X        state=x ;;
  106. X    esac
  107. Xdone
  108. X#
  109. Xcase "${newsgroup}${file}${directory}${mailto}" in
  110. X?*)    $cat - > $ARTICLE ;;
  111. X*)    exec $Mail -s "No options to /local/lib/mail/distribute" rayan
  112. X    exec /bin/mail rayan
  113. X    exit 4 ;;
  114. Xesac
  115. Xcase $file in
  116. X?*)    $blankcat -lists/${file} $ARTICLE ;;
  117. Xesac
  118. Xcase $directory in
  119. X?*)    eval `/usr/ucb/head -40 $ARTICLE \
  120. X    | /usr/bin/fgrep -i digest \
  121. X    | /bin/sed -n \
  122. X    -e 's/.*Vol[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^0-9]*/VOL=\1 NUM=\2/p'`
  123. X    $blankcat "-$directory/V${VOL}.${NUM}" $ARTICLE ;;
  124. X*)    directory="$archdir" ;;
  125. Xesac
  126. X
  127. X# extract return path from article
  128. X/local/bin/ed - $ARTICLE <<EOF
  129. X1s/From \\([^ ]*\\) .*/\\1/
  130. X1w $ARTICLE.from
  131. X1d
  132. Xw
  133. Xq
  134. XEOF
  135. X
  136. X# forwarding via mail
  137. Xif [ -s $ARTICLE.from ]; then
  138. X    path="`cat $ARTICLE.from`"
  139. X    case $mailto in
  140. X    */*)    ( cd $directory ;
  141. X        if [ -s $mailto ]; then
  142. X            $sendmail -f $path `cat $mailto` < $ARTICLE
  143. X        fi
  144. X        )
  145. X        ;;
  146. X    ?*)    $sendmail -f $path $mailto < $ARTICLE
  147. X        ;;
  148. X    esac
  149. Xelse
  150. X    path="$newsserver!news"
  151. Xfi
  152. X
  153. X# forwarding to newsgroups
  154. Xcase $newsgroup in
  155. X?*)    case $path in
  156. X    *!*!*)    path="`expr $path : '.*!\([^!]*![^!]*\)$'`"
  157. X        case $path in
  158. X        *.*!*)    ;;
  159. X        *)    path="`echo $path | sed 's/!/.uucp&/'`" ;;
  160. X        esac ;;
  161. X    *!*)    ;;
  162. X    *)    path="`hostname`.toronto.edu!$path" 
  163. X    esac
  164. X# All this does is massage the headers so they look like what news
  165. X# software expects.  To:, Cc: and Resent-*: headers are masked.
  166. X# Reply-To: is turned into references, which is questionable (could
  167. X# just as well be dropped.
  168. X#
  169. X# The From: line is rewritten to use the "address (comments)" form
  170. X# instead of "phrase <route>" form our mailer uses.  Also, addresses
  171. X# with no "@domainname" are assumed to originate locally, and so are
  172. X# given a domain.
  173. X#
  174. X# The Sender: field below reflects the address of the person who
  175. X# maintains our mailing lists.  The Approved: field is in a special
  176. X# form, so that we can do bidirectional gatewaying.  Any message
  177. X# in a newsgroup that bears this stamp will not be fed into the
  178. X# matching mailing list.
  179. X    sed -n -e "1{i\\
  180. X        Path: $path
  181. X        }" \
  182. X        -e ":a
  183. X        /^[Rr]eceived:/b r
  184. X        /^[Tt][Oo]:/s/^/Original-/
  185. X        /^[Cc][Cc]:/s/^/Original-/
  186. X        /^[Rr][Ee][Ss][Ee][Nn][Tt]-.*/s/^/Original-/
  187. X        s/^[Ii]n-[Rr]eply-[Tt]o:/References:/
  188. X        /^From:/{
  189. X            s/<\([^@]*\)>\$/<\1@$thissite>/
  190. X            s/^From:[     ][    ]*\(.*\)  *<\(.*\)>\$/From: \2 (\1)/
  191. X            }
  192. X        s/-[Ii]d:/-ID:/
  193. X        s/^\([^:]*:\)[     ]*/\1 /
  194. X        /^\$/{i\\
  195. X            Newsgroups: $newsgroup\\
  196. X            Distribution: $distribution\\
  197. X            Sender: $admin@$thissite\\
  198. X            Approved: $newsgroup@mail.ai.toronto.edu
  199. X            b e
  200. X        }
  201. X        p
  202. X        n
  203. X        b a
  204. X        :r
  205. X        s/.*//g
  206. X        n
  207. X        /^[     ]/b r
  208. X        b a
  209. X        :e
  210. X        p
  211. X        n
  212. X        b e" < $ARTICLE > ${ARTICLE}.news
  213. X# ${ARTICLE}.news is the article to be posted.  Any method could
  214. X# be used to do it, normally invoking "inews" or even "relaynews" 
  215. X# directly would work.  Our setup is peculiar in that the news server
  216. X# is another machine, for historical (hysterical?) reasons.
  217. X# It turns out that invoking nntp on each article puts more load on
  218. X# the news server than making up a fake batch and mailing it to them,
  219. X# so we do just that.
  220. X        set - `wc -c ${ARTICLE}.news`
  221. X        (echo "#! rnews $1" ; cat ${ARTICLE}.news) |
  222. X            sed -e 's/^/N/' |
  223. X            $sendmail -f"$admin" recnews@jarvis.csri
  224. X#
  225. X# update the logs
  226. X#
  227. X        messageid=`egrep -i '^message-id:[     ]' $ARTICLE`
  228. X        messageid=`expr "$messageid" : '..........:[     ]\(.*\)'`
  229. X        time=`date | awk '{print $2,$3,$4}'`
  230. X        echo $time $newsgroup $messageid >> $LOG
  231. Xesac
  232. X$rm -f $ARTICLE $ARTICLE.from $ARTICLE.news
  233. Xexit 0
  234. !
  235. echo 'contrib/nntpmail/mailing_lists/mailgateway':
  236. sed 's/^X//' >'contrib/nntpmail/mailing_lists/mailgateway' <<'!'
  237. X#!/bin/sh
  238. X#
  239. X# mailgateway recipients
  240. X#
  241. X# bidirectional gatewaying utility.
  242. X#
  243. X# - forward a news article to recipients (typically a single alias in
  244. X#   /usr/lib/aliases or equivalent, to avoid long lists of recipients in 
  245. X#   messages)
  246. X# - filter out news control message.
  247. X# - messages fed to the newsgroup from the mailing list are not sent back.
  248. X#   we assume that "distribute" did the feed, and we look for the tell-tale
  249. X#   "Approved" line it tacks on to messages.
  250. X#
  251. X# Jean-Francois Lamy (lamy@ai.toronto.edu) 88-02-27
  252. X
  253. Xmagic="@mail.ai.toronto.edu"  # what distribute uses in Approved: line
  254. Xmail="/usr/lib/sendmail -t"
  255. Xarticle=/tmp/art$$
  256. X
  257. Xcase $# in
  258. X0) echo "$0: no argument (check /usr/lib/news/sys)" | $mail usenet
  259. X   exit 1 ;;
  260. X*) ;;
  261. Xesac
  262. Xcat >$article
  263. X
  264. Xcheck=`awk '
  265. X   /^Subject: cmsg/         { print "nope" ; exit }
  266. X   /^Control:/             { print "nope" ; exit }
  267. X   /^$|^[ ][ \t]*$/         { exit }
  268. X                 { next }
  269. X   ' $article`
  270. X
  271. Xif [ ! "$check" ] ; then
  272. X   if /bin/grep -s $magic $article ; then
  273. X       : came from distribute
  274. X   else
  275. X          (
  276. X       echo "rcvdfrom USENET"  # zmailer feature, delete for sendmail.
  277. X       echo "To: $@"
  278. X       cat $article ) | $mail
  279. X   fi
  280. Xfi
  281. X/bin/rm -f $article
  282. !
  283. echo 'contrib/nntpmail/mailing_lists/moderate':
  284. sed 's/^X//' >'contrib/nntpmail/mailing_lists/moderate' <<'!'
  285. X#!/bin/sh
  286. X# moderate owner distribution-alias
  287. X#
  288. X# ensure message gets redistributed to a distribution list alias yet
  289. X# error messages come back to the list owner.  This requires invoking
  290. X# the mailer again.
  291. X#
  292. X# A mailing list is then set-up by adding aliases as follows: (articles are
  293. X# mailed to example, administrivia to example-request, error messages go back
  294. X# to example-owner, and the list of recipients is example-people).
  295. X#
  296. X# example: "|/local/lib/mail/bin/moderate example-owner example-people"
  297. X# example-request: lamy
  298. X# example-owner: lamy
  299. X# example-people: ":include:/local/share/mail/lists/example"
  300. X#
  301. X# note that your sendmail may not want the " around the :include, but
  302. X# that zmailer does in the name of RFC-822...
  303. X
  304. Xowner=$1;shift
  305. Xrecipients=$@
  306. Xcat > /tmp/$owner$$
  307. X/bin/ed - /tmp/$owner$$ <<EOF 2>/dev/null
  308. X1d
  309. X/^[Ff][Rr][Oo][Mm]:/t0
  310. X/^\$/i
  311. XResent-From: $owner
  312. XResent-To: $recipients
  313. X.
  314. X1m.
  315. Xs/^From:/Resent-Reply-To:/
  316. Xs/:    */: /
  317. Xw
  318. Xq
  319. XEOF
  320. X
  321. X/usr/lib/sendmail -t -f$owner  < /tmp/$owner$$
  322. X/bin/rm -f /tmp/$owner$$
  323. !
  324. echo 'contrib/nntpmail/nntp_support/README':
  325. sed 's/^X//' >'contrib/nntpmail/nntp_support/README' <<'!'
  326. XThis directory contains C news support for posting news via NNTP.
  327. X
  328. Xfrontend_inews    parse options, invokes $NEWSBIN/nntp/inews to
  329. X        send the article to the remote NNTP server.
  330. X
  331. X$NEWSBIN/nntp/inews
  332. X        not included here, you can get the NNTP distribution
  333. X        from UCSD.EDU and apply the patches found on
  334. X        bcm.tmc.edu.  This is the C program that sends    
  335. X        the article to a remote server
  336. X
  337. Xserver_inews    if you run an NNTP server, it should call this as its
  338. X        inews (fix common/conf.h).  figures out moderated newsgroups
  339. X        and all that.
  340. X
  341. X            To repeat: make sure the nntp server invokes server_inews and
  342. X        not $NEWSBIN/nnpt/news (instant infinite loop!).
  343. !
  344. echo 'contrib/nntpmail/nntp_support/frontend_inews':
  345. sed 's/^X//' >'contrib/nntpmail/nntp_support/frontend_inews' <<'!'
  346. X#! /bin/sh
  347. X# inews [-p] [-debug k] [-x site] [-hMD] [-t subj] [-n ng] [-e exp] [-F ref] \
  348. X#  [-d dist] [-a mod] [-f from] [-o org] [-C ng] [file...] - inject news:
  349. X#    censor locally-posted article and field the "inews -C" kludge;
  350. X#    munge the articles, enforce bogus and pathetic attempts at
  351. X#    Usenet security, generate lotsa silly headers.
  352. X# =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  353. X. ${NEWSCONFIG-/news/bin/config}
  354. Xexport NEWSCTL NEWSBIN NEWSARTS NEWSPATH NEWSUMASK NEWSMASTER NEWSCONFIG
  355. XPATH=$NEWSCTL/bin:$NEWSBIN/inject:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH; export PATH
  356. XPASSEDFROM='';    export PASSEDFROM    # passed to anne.jones in environ.
  357. X
  358. Xdebug=''            # flags
  359. Xexclusion=''
  360. Xhdrspresent=no
  361. Xautopost=no
  362. Xwaitcmd=''
  363. Xrelayopts=-i            # redirect stdout to log
  364. X
  365. Xwhoami=/tmp/in$$who        # just created to determine effective uid
  366. Xinput=/tmp/in$$in        # uncensored input
  367. Xinhdrs=/tmp/in$$hdr        # generated by tear: headers
  368. Xinbody=/tmp/in$$body        # generated by tear: body
  369. Xcensart=/tmp/in$$cens        # censored input
  370. Xnglist=/tmp/in$$ngs        # newsgroups: list
  371. Xmodroute=/tmp/in$$route        # route to moderator's forwarder
  372. Xexitflag=/tmp/in$$exit        # exit status, if present
  373. Xoutfile=/tmp/in$$out        # relaynews stdout
  374. Xgrpok=/tmp/in$$grp        # flag file: groups okay if present
  375. Xrmlist="$inhdrs $inbody $input $censart $nglist $modroute $exitflag $outfile $grpok"
  376. X
  377. Xumask $NEWSUMASK
  378. X
  379. X# "inews -p": invoke rnews
  380. Xcase "$1" in
  381. X-p)
  382. X    shift
  383. X    exec rnews $*        # rnews, bailing out at or near line 1
  384. X    ;;
  385. Xesac
  386. X
  387. X# parse arguments: for options, cat headers onto $input; cat files onto $input
  388. X>$input
  389. Xcleanup="test ! -f $HOME/dead.article -o -w $HOME/dead.article &&
  390. X  cat $input >>$HOME/dead.article &&
  391. X  { echo $0: article in $HOME/dead.article >&2; rm -f $rmlist; }; exit 1"
  392. Xtrap "$cleanup" 0 1 2 3 15
  393. Xwhile :
  394. Xdo
  395. X    case $# in
  396. X    0)    break ;;        # arguments exhausted
  397. X    esac
  398. X
  399. X    case "$1" in
  400. X    # peculiar to C news
  401. X    -debug)    shift; debug="$1" ;;
  402. X    -A)    autopost=yes ;;        # wait for free space
  403. X    -V)    relayopts= ;;        # verbose: don't redirect stdout (or stderr)
  404. X    -W)    waitcmd=wait ;;        # wait for completion
  405. X    # useful standard options
  406. X    -h)    hdrspresent=yes ;;
  407. X    -x)    shift; exclusion="-x $1" ;;    # you're welcome, erik (2.11)
  408. X    # silly options supplied by newsreaders
  409. X    -a)    shift; echo "Approved: $1" >>$input ;;
  410. X    -c)    shift; echo "Control: $1" >>$input ;;
  411. X    -d)    shift; echo "Distribution: $1" >>$input ;;
  412. X    -e)    shift; echo "Expires: $1" >>$input ;;
  413. X    -n)    shift; echo "Newsgroups: $1" >>$input ;;
  414. X    -t)    shift; echo "Subject: $1" >>$input ;;    # aka Title:
  415. X    -D)    # obsolete, undocumented: meant "don't check for recordings".
  416. X        # last present in B 2.10.1, invoked by readnews for followups.
  417. X        ;;
  418. X    -F)    # undocumented in B 2.10.1, documented in B 2.11.
  419. X        shift; echo "References: $1" >>$input ;;
  420. X    -M)    # this apparently just sets From: to the author of the article
  421. X        # instead of the poster (moderator), by leaving the From: line
  422. X        # alone (under -h); easy to implement.
  423. X        ;;
  424. X
  425. X    # pass next options as environment variables to anne.jones
  426. X    -f)    shift; PASSEDFROM="$1" ;;    # complex due to Sender:
  427. X    -o)    shift; ORGANIZATION="$1"; export ORGANIZATION ;;
  428. X
  429. X    -C)    # megakludge-o-rama
  430. X        # first, permit only to super-users
  431. X        >$whoami
  432. X        case "`ls -l $whoami | awk '{print $3}'`" in
  433. X        root)    : a winner ;;
  434. X        *)
  435. X            echo "$0: only super-users may create news groups" >&2
  436. X            exit 1
  437. X            ;;
  438. X        esac
  439. X        rm -f $whoami
  440. X
  441. X        inewsopt="$1"        # for use in message body
  442. X        shift            # skip -C to get ng as $1
  443. X
  444. X        cat <<! >>$input    # generate a control message
  445. XNewsgroups: $1
  446. XControl: newgroup $1
  447. XSubject: newgroup $1
  448. XApproved: above-user@above-host
  449. X
  450. XThis article generated by inews $inewsopt $1.
  451. X!
  452. X        ;;
  453. X    -*)
  454. X        echo "$0: bad option $1" >&2
  455. X        exit 1
  456. X        ;;
  457. X    *)                    # is a filename; append file
  458. X        # B 2.11 kludge: assume -h if input starts with headers.
  459. X        # apparently the B 2.11 newsreaders assume this.
  460. X        tear /tmp/in$$ <$1
  461. X        if test -s $inhdrs; then
  462. X            hdrspresent=yes
  463. X        fi
  464. X
  465. X        case "$hdrspresent" in
  466. X        no)    echo "" >>$input; hdrspresent=yes ;;
  467. X        esac
  468. X        # capture incoming news in case relaynews fails
  469. X        if cat $inhdrs $inbody >>$input; then
  470. X            : far out
  471. X        else
  472. X            echo "$0: lost news; cat status $?" >&2
  473. X            exit 1
  474. X        fi
  475. X        fileseen=yes
  476. X        ;;
  477. X    esac
  478. X    shift        # pass option or filename (any value was done above)
  479. Xdone
  480. X
  481. X# if no files named, read stdin
  482. Xcase "$fileseen" in
  483. Xyes)    ;;
  484. X*)
  485. X    # B 2.11 kludge: assume -h if input starts with headers
  486. X    # apparently the B 2.11 newsreaders assume this.
  487. X    tear /tmp/in$$
  488. X    if test -s $inhdrs; then
  489. X        hdrspresent=yes
  490. X    fi
  491. X
  492. X    case "$hdrspresent" in
  493. X    no)    echo "" >>$input; hdrspresent=yes ;;
  494. X    esac
  495. X    # capture incoming news in case relaynews fails
  496. X    if cat $inhdrs $inbody >>$input; then
  497. X        : far out
  498. X    else
  499. X        echo "$0: lost news; cat status $?" >&2
  500. X        exit 1
  501. X    fi
  502. X    ;;
  503. Xesac
  504. Xtrap '' 1 2 15            # ignore signals to avoid losing articles
  505. X
  506. X# run the remainder in the background for the benefit of impatient people
  507. X# who lack a window system
  508. X(
  509. Xtrap "$cleanup" 0
  510. Xtear /tmp/in$$ <$input        # output in $inhdrs and $inbody
  511. X# pad zero-line articles, since old B [ir]news are confused by them
  512. X# and the news readers generate zero-line control messages, alas.
  513. Xif test ! -s $inbody; then
  514. X    (echo '';
  515. X     echo This article was probably generated by a buggy news reader.) \
  516. X     >$inbody
  517. Xfi
  518. X
  519. X# deduce which tr we have: v6 or v7
  520. Xcase "`echo B | tr A-Z a-z `" in
  521. Xb)    trversion=v7 ;;
  522. XB)    trversion=v6 ;;            # or System V
  523. Xesac
  524. Xexport trversion
  525. X
  526. X# post with new headers and .signature
  527. X(anne.jones <$inhdrs        # bash headers
  528. X # echo "Lines: `        # sop to msb, just uncomment to use
  529. X # if test -r $HOME/.signature; then
  530. X #    (cat $inbody; echo "-- "; sed 4q $HOME/.signature) | wc -l
  531. X # else
  532. X #    wc -l <$inbody
  533. X # fi
  534. X # `"
  535. X
  536. X # strip invisible chars from body, a la B news
  537. X case "$trversion" in
  538. X v7)    tr -d '\1-\7\13\14\16-\37' ;;
  539. X v6)    tr -d '[\1-\7]\13\14[\16-\37]' ;;
  540. X esac <$inbody
  541. X
  542. X# the NNTP server does this.
  543. X# if test -r $HOME/.signature; then
  544. X#    echo "-- "; sed 4q $HOME/.signature    # glue on first bit of signature
  545. X# fi
  546. X) >$censart
  547. X
  548. X# do the deed...
  549. X
  550. X$NEWSBIN/nntp/inews <$censart
  551. Xstatus=$?
  552. X
  553. Xcase "$status" in
  554. X0)
  555. X    rm -f $rmlist            # far out, it worked: clean up
  556. X    trap 0                # normal exit: cleanup done
  557. X    ;;
  558. Xesac
  559. Xexit $status                # trap 0 may cleanup, make dead.article
  560. X) &
  561. X$waitcmd                # wait if -W given
  562. Xtrap 0                    # let the background run on unmolested
  563. Xexit
  564. !
  565. echo 'contrib/nntpmail/nntp_support/server_censor':
  566. sed 's/^X//' >'contrib/nntpmail/nntp_support/server_censor' <<'!'
  567. X#! /bin/sh
  568. X# server.censor - censor headers, assuming input is a mail message.
  569. X#               Some details depend on UofT CSRI environment.
  570. X#        Jean-Francois Lamy, 1987-11-02
  571. X#
  572. XPATH=/bin:/usr/bin; export PATH
  573. XNEWSCTL=${NEWSCTL-/usr/lib/news}; export NEWSCTL
  574. XNEWSBIN=${NEWSBIN-/usr/lib/newsbin}; export NEWSBIN
  575. XNEWSARTS=${NEWSARTS-/usr/spool/news}; export NEWSARTS
  576. X
  577. X# pass 0 - dredge up defaults
  578. Xhost="`hostname`.toronto.edu"
  579. Xdefdate="`set \`date\`; echo $1, $3-$2-\`echo $6 | sed 's/^..//'\` $4 $5`"
  580. Xdefmsgid="`set \`date\`; echo \<$6$2$3.\`echo $4 | tr -d :\`.$$@$host\>`"
  581. X
  582. Xsed -e "s/DEFMSGID/$defmsgid/" -e "s/DEFDATE/$defdate/" <<\! >/tmp/aj$$awk 
  583. X
  584. X# pass 1 - note presence | absence of certain headers
  585. X
  586. X# a header keyword: remember it and its value
  587. X/^[^\t ]*:/ { hdrval[$1] = $0; keyword=$1 }
  588. X# a continuation: concatenate this line to the value
  589. X!/^[^\t ]*:/ { hdrval[keyword] = hdrval[keyword] "\n" $0 }
  590. X
  591. XEND {
  592. X    # pass 2 - deduce & omit & emit headers
  593. X    subjname = "Subject:"
  594. X    ctlname = "Control:"
  595. X    ngname = "Newsgroups:"
  596. X    msgidname = "Message-ID:"
  597. X    typoname =  "Message-Id:"
  598. X    pathname = "Path:"
  599. X    datename = "Date:"
  600. X    fromname = "From:"
  601. X    orgname = "Organization:"
  602. X    distrname = "Distribution:"
  603. X
  604. X    # fill in missing headers
  605. X    if (hdrval[typoname] != "") {    # spelling hack
  606. X        hdrval[msgidname] = hdrval[typoname]
  607. X        hdrval[typoname] = ""
  608. X        # fix spelling: Message-Id: -> Message-ID:
  609. X        nf = split(hdrval[msgidname], fields);    # bust up
  610. X        fields[1] = msgidname;        # fix spelling
  611. X        hdrval[msgidname] = fields[1];    # reassemble...
  612. X        for (i = 2; i <= nf; i++)
  613. X            hdrval[msgidname] = hdrval[msgidname] " " fields[i]
  614. X    }
  615. X
  616. X    # We trust From:, Date: and Message-ID: as generated by mailer.
  617. X    # hdrval[datename] = datename " " "DEFDATE" # in case Date: breaks news
  618. X
  619. X    # NNTP POST command may forget to put a message ID...
  620. X    
  621. X    if (hdrval[msgidname] == "")
  622. X        hdrval[msgidname] = msgidname " " "DEFMSGID"
  623. X    
  624. X    # snuff some headers
  625. X    distworld = distrname " world"
  626. X    if (hdrval[distrname] == distworld)
  627. X        hdrval[distrname] = ""
  628. X
  629. X    # turn Subject: cmsg into a proper Control: header.
  630. X    if (substr(hdrval[subjname],1,14) == "Subject: cmsg ")
  631. X        hdrval[ctlname] = ctlname " " substr(hdrval[subjname],15)
  632. X
  633. X    # warn if no Newsgroups:
  634. X    if (hdrval[ngname] == "")
  635. X        print "no newsgroups header!" | "cat >&2"
  636. X
  637. X    # favour Newsgroups: & Control: for benefit of rnews
  638. X    if (hdrval[ngname] != "") {
  639. X        print hdrval[ngname]
  640. X        hdrval[ngname] = ""    # no Newsgroups: to print now
  641. X    }
  642. X    if (hdrval[ctlname] != "") {
  643. X        print hdrval[ctlname]
  644. X        hdrval[ctlname] = ""    # no Control: to print now
  645. X    }
  646. X
  647. X    # B news kludgery: print Path: before From:
  648. X    if (hdrval[pathname] != "") {
  649. X        print hdrval[pathname]
  650. X        hdrval[pathname] = ""    # no Path: to print now
  651. X    }
  652. X    if (hdrval[fromname] != "") {
  653. X        print hdrval[fromname]
  654. X        hdrval[fromname] = ""    # no From: to print now
  655. X    }
  656. X
  657. X    # have pity on readers: put Subject: next
  658. X    if (hdrval[subjname] != "") {
  659. X        print hdrval[subjname]
  660. X        hdrval[subjname] = ""    # no Subject: to print now
  661. X    }
  662. X
  663. X    # print misc. headers in random order, unless they are empty.
  664. X    for (i in hdrval)
  665. X        if (hdrval[i] != "" && hdrval[i] != i " ")
  666. X            print hdrval[i]
  667. X}
  668. X!
  669. Xcat $* | 
  670. Xsed -e 's/^From:[     ]*\(.*\)  *<\(.*\)>/From: \2 \(\1\)/' \
  671. X    -e '/^Received:/d' \
  672. X    -e '/^To:/d' \
  673. X    -e '/^X-To:/d' \
  674. X    -e '/^Cc:/d' \
  675. X    -e 's/^Original-//' |
  676. Xtr -d '\1-\7\13\14\16-\37' |    # strip invisible chars, a la B news
  677. X    awk -f /tmp/aj$$awk
  678. Xrm -f /tmp/aj$$awk
  679. !
  680. echo 'contrib/nntpmail/nntp_support/server_inews':
  681. sed 's/^X//' >'contrib/nntpmail/nntp_support/server_inews' <<'!'
  682. X#! /bin/sh -
  683. X#
  684. X# server_inews 
  685. X#
  686. X#   Post article read on stdin.  Arguments are ignored. 
  687. X#   Meant to be invoked by an NNTP server or by a sendmail/zmailer alias (e.g.
  688. X#   feednews: "|/news/bin/server_inews" )
  689. X#
  690. X#   We assume that the From: line can be trusted and if a Path: line is not
  691. X#   present we fake one using the mail path so broken users that rely on it
  692. X#   get a reply address that way.
  693. X#
  694. X#   The message is mailed to moderators of moderated newsgroups mentioned on
  695. X#   the Newsgroups: line, unless a proper Approved: line is seen, in which
  696. X#   case we post directly.
  697. X#
  698. X# original code from Geoff Collyer, C news alpha release
  699. X# heavily reworked for CSRI/ANT environment by Jean-Francois Lamy
  700. X#    (lamy@ai.toronto.edu)
  701. X
  702. XNEWSCTL=${NEWSCTL-/usr/lib/news}
  703. XNEWSBIN=${NEWSBIN-/usr/lib/newsbin}
  704. XNEWSARTS=${NEWSARTS-/usr/spool/news}
  705. XPATH=$NEWSCTL:/usr/lib/news:$NEWSBIN:$NEWSBIN/relay:/bin:/usr/bin:/usr/ucb
  706. Xexport PATH
  707. X
  708. Xdebug=''        # flags
  709. Xexclusion=''
  710. X
  711. Xhostname=`hostname`
  712. X
  713. Xinput=/tmp/in$$in          # uncensored input
  714. Xfrom=/tmp/in$$from      # return path extracted from From_ or Return-Path: line
  715. Xinhdrs=/tmp/in$$hdr    # generated by tear: headers
  716. Xinbody=/tmp/in$$body    # generated by tear: body
  717. Xcensart=/tmp/in$$cens   # article with censored headers
  718. Xnglist=/tmp/in$$ngs     # newsgroups: raw list with commas
  719. Xngfile=/tmp/in$$ngc    # newsgroups, one per line
  720. Xrtefile=/tmp/in$$rte    # route chosen for each moderated newsgroup
  721. Xrmlist="$inhdrs $inbody $input $from\
  722. X        $censart $nglist $ngfile $modfile $rtefile"
  723. X                       
  724. X# articles plainly mailed to moderators
  725. Xsendnews="/usr/lib/sendmail -t"
  726. X
  727. Xumask 2
  728. Xtrap '' 1 2 15         # ignore signals to avoid losing articles
  729. X
  730. X# capture incoming news in case inews fails
  731. X   if cat >>$input; then
  732. X      : got it.
  733. X   else
  734. X      echo "$0: lost news; cat status $?" >&2
  735. X      exit 1
  736. X   fi
  737. X
  738. X
  739. X# We separate the header from the body.
  740. X   >>$inbody; >>$censart
  741. X   awk 'BEGIN             { inbody = 0 }
  742. X   inbody != 0             { print $0 >"'$inbody'"; next}
  743. X   inbody == 0 && /^$|^[ ][ \t]*$/ { inbody = 1; print "" >"'$inbody'"; next }
  744. X   inbody == 0             { print $0 >"'$censart'" ; next }
  745. X   ' $input
  746. X
  747. X# Extract information from From_ or Return-Path line so that we can give it
  748. X# back to the mailer (we want mail to the moderator to look as if it came from
  749. X# the originator himself).  We then mutate it into a Path: header.
  750. X# if there is a Path: header (e.g. if we are invoked from NNTP, we use that.
  751. X   sed -e '1s/^From \([^ ]*\) .*$/Path: \1/' \
  752. X       -e 's/^Return-Path: \([^ ]*\).*$/Path: \1/' \
  753. X       -e '/^Path: /{
  754. X           s/^Path: \([^ ]*\).*$/\1/
  755. X           s/.*'$hostname'[^!]*!//
  756. X           w '$from'
  757. X           s/^/Path: /
  758. X           }' \
  759. X       -e '/^[     ]*$/q'    <$censart >$inhdrs
  760. X
  761. X
  762. X# produce list of newsgroups
  763. X   sed -n '/^Newsgroups:[ ]/{
  764. X      s/^Newsgroups:[ ]*\(.*\)$/\1/p
  765. X      q
  766. X      }' <$inhdrs >$nglist
  767. X
  768. X# control messages are special: newgroup messages belong to inexistent
  769. X# newsgroups (makes sense) and names with .ctl don't appear in the active file
  770. X# either.  We force a trailing .ctl on newsgroup names so that downstream
  771. X# sites can prevent control articles from getting on mail redistributions
  772. X#
  773. X# Remove tabs after : so that the rest of the world accepts our postings.
  774. X   read ng <$nglist
  775. X   if egrep "^Control:|^Subject: cmsg" $inhdrs >/dev/null ; then
  776. X       ( server_censor <$inhdrs |
  777. X     sed -e '/^Newsgroups:/{
  778. X                  s/.ctl//g
  779. X          s/,/.ctl,/g
  780. X          s/$/.ctl/g
  781. X          }' \
  782. X          -e 's/^\([^:]*:\)[     ]*/\1 /'
  783. X     tr -d '\1-\7\13\14\16-\37' <$inbody
  784. X       ) >$censart
  785. X       relaynews -r <$censart
  786. X       rm $rmlist
  787. X       exit 0
  788. X   fi
  789. X
  790. X# handle non control messages.  Unknown newsgroups are dropped, as per RFC1036
  791. X# Too bad if Pnews, postnews or the Zmailer router did not complain
  792. Xegrep "^(` sed -e 's/\./\\\\./g' \
  793. X           -e 's/+/\\\\+/g'  \
  794. X               -e 's/,/ |/g'     \
  795. X               -e 's/$/ /' <$nglist`)" \
  796. X   $NEWSCTL/active >$ngfile
  797. Xexec <$ngfile
  798. Xwhile read ng high low flag   # look at next group's active entry
  799. Xdo
  800. X   case "$flag" in
  801. X   n)
  802. X      echo "$0: $ng may not be posted to." >&2
  803. X      echo "$0: message not sent anywhere." >&2
  804. X      exit 64   # sendmail/Zmailer "bad usage" message
  805. X      ;;
  806. X   m)
  807. X      if grep -s '^Approved:[    ]' $inhdrs; then # just post normally
  808. X         approved=1
  809. X     newsgroups=${newsgroups+$newsgroups,}$ng
  810. X      else # un-Approved: add moderator to list of recipients
  811. X     # look for route for this group
  812. X     while read ngpat route
  813. X     do
  814. X        # a dreadful B 2.11 hack: backbone|internet == all
  815. X           case "$ngpat" in
  816. X           backbone|internet) ngpat="all" ;;
  817. X           esac
  818. X        # we assume that mailpath file has proper wildcards at the
  819. X        # end, i.e. we always exit via this break.
  820. X           if (echo $ng $route| gngp -a "$ngpat" >/dev/null) ; then
  821. X             echo $route >$rtefile
  822. X             break
  823. X           fi
  824. X     done <$NEWSCTL/mailpaths
  825. X
  826. X     # add to list of moderators unless no moderator is found
  827. X     # (local newsgroups are assumed to have a catch-all pattern
  828. X     # to provoke errors)
  829. X         route=`cat $rtefile`
  830. X     if [ "$route" = "error" ] ; then
  831. X        echo "$0: no moderator found for news group '$ng'" >&2
  832. X        echo "$0: message not sent anywhere." >&2
  833. X        exit 64 # bad usage message.
  834. X     else
  835. X        modroute=${modroute+$modroute,}$route
  836. X     fi
  837. X      fi
  838. X      ;;
  839. X   y)
  840. X      newsgroups=${newsgroups+$newsgroups,}$ng
  841. X      ;;
  842. X   esac
  843. Xdone
  844. X
  845. X# $censart is used rather than a pipe to work around a bug in the 4.2
  846. X# sh which makes it sometimes return the wrong exit status
  847. X
  848. Xif [ "$modroute" ] ; then
  849. X   # mail article to the moderator(s)
  850. X   # Remove headers that may break mailers or cause loops.
  851. X   # strip invisible chars from body, a la B news
  852. X      ( sed -e '/^Newsgroups:/d' -e '/^Path:/d' \
  853. X        -e '/^To:/d' -e '/^Cc:/d' < $inhdrs
  854. X    echo "To: ${modroute}"
  855. X    tr -d '\1-\7\13\14\16-\37' <$inbody
  856. X      ) >$censart
  857. X      $sendnews -f"`cat $from`" <$censart
  858. Xfi
  859. X
  860. Xif [ "$newsgroups" ] ; then
  861. X   # feed article to news.  Put in cleaned-up newsgroups line (no remote
  862. X   # moderated newsgroups appear).  If a local user posts to a newsgroup with
  863. X   # a local moderator then the approved article does not get posted because
  864. X   # the news server is already in the path.  We fix that with a chain-saw,
  865. X   # pending resolution of the bug in the news relaying software...
  866. X   # strip invisible chars from body, a la B news
  867. X      ( server.censor <$inhdrs |
  868. X    sed ${approved+-e} ${approved+"s/^Path:.*$hostname!/Path: /"} \
  869. X        -e "s/^Newsgroups:.*\$/Newsgroups: $newsgroups/" \
  870. X           -e 's/^\([^:]*:\)[     ]*/\1 /'
  871. X    tr -d '\1-\7\13\14\16-\37' <$inbody
  872. X      ) >$censart
  873. X
  874. X   if relaynews -r <$censart
  875. X   then
  876. X      rm -f $rmlist      # far out, it worked
  877. X      if [ -s $NEWSCTL/dig.twimc ]; then
  878. X     $NEWSBIN/digestify $NEWSCTL/dig.twimc
  879. X      fi
  880. X      exit 0
  881. X   else
  882. X      status=$?
  883. X      echo "$0: article could not be posted (relaynews status $status)" >&2
  884. X      echo "$0: failed news in `hostname`:$input " >&2
  885. X      exit $status
  886. X   fi
  887. Xelse
  888. X   rm -f $rmlist
  889. X   exit 0
  890. Xfi
  891. !
  892. echo 'contrib/nntpmail/mail_to_group/README':
  893. sed 's/^X//' >'contrib/nntpmail/mail_to_group/README' <<'!'
  894. XPOSTING VIA MAIL
  895. X
  896. XWe wanted our users to be able to mail to the newsgroups, so we wrote a
  897. Xsendmail/zmailer transport agent to support this.  You must edit your
  898. Xmailer configuration file so that mail to a newsgroup gets sent to that
  899. Xuser agent.  The default router.cf distributed with zmailer does that.
  900. X
  901. Xusenet:          sendmail-compatible transport agent.  Our mailer invokes it on 
  902. X              local names it can find in the active newsgroup file, so the 
  903. X          message gets posted.  usenet then arranges for a real inews
  904. X          to get invoked by either
  905. X          a) calling inews itself
  906. X          b) pushing the message with NNTP to a news server
  907. X             (see ../nntp_support)
  908. X          c) remailing the message to a news server
  909. X             (inferior to b, but it can be made to work. see
  910. X         ../fake_nntp_via_mail)
  911. X
  912. XPosting via mail ensures proper return addresses and automagically supports
  913. Xwhatever fancy processing the mailer does (hiding workstation names, producing
  914. XFull.Name@do.ma.in forms, whatever), In fact, we changed our set-up to use a
  915. Xfake inews that mails the article to the newsgroups.
  916. X
  917. Xfrontend_inews
  918. X          This fake inews parses the arguments and mails to the list
  919. X          of newsgroups so that the From: and other headers get generated
  920. X          by a program that really knows what it is doing.  The mailer
  921. X          will then arrange for injection in the news flow.
  922. X
  923. X          This inews gets invoked by Pnews et al.  It would traditionally
  924. X          go in /usr/lib/news/inews.  Make sure that it does not get
  925. X          invoked by NNTP on a news server, for that would cause a nice
  926. X          infinite loop.
  927. X
  928. !
  929. echo 'contrib/nntpmail/mail_to_group/ROADMAP':
  930. sed 's/^X//' >'contrib/nntpmail/mail_to_group/ROADMAP' <<'!'
  931. XThe news setup around {ai,theory,na}.toronto.edu looks
  932. Xroughly like this:
  933. X
  934. X      inews (really frontend_inews)
  935. X        |
  936. X        | The article is turned into a mail message by inews.
  937. X    |
  938. X  mail comp.whatever,...
  939. X        |
  940. X        | at this point proper return addresses are on, etc.
  941. X    |
  942. X   usenet transport agent
  943. X    |
  944. X    | NNTP (or mail to feednews@news-server)
  945. X    |
  946. X  news-server.csri
  947. X    |
  948. X        |  NNTP server (if mail to feednews, alias that pipes to server_inews)
  949. X    |
  950. X    server_inews (figures out if group is moderated and so on)
  951. X    |
  952. X     |
  953. X    |
  954. X     relaynews (actual posting)
  955. !
  956. echo 'contrib/nntpmail/mail_to_group/frontend_inews':
  957. sed 's/^X//' >'contrib/nntpmail/mail_to_group/frontend_inews' <<'!'
  958. X#! /bin/sh
  959. X# inews [-p] [-d k] [-x site] [-hMD] [-t subj] [-n ng] [-e exp] [-F ref] \
  960. X#  [-d dist] [-a mod] [-f from] [-o org] [-C ng] [file...] - inject news:
  961. X#
  962. X# pseudo-inews that posts by mailing the message, so that whatever
  963. X# fancy processing the mailer does to generate a return address
  964. X# takes place.
  965. X#
  966. X# The mailer normally ends up invoking a "usenet" transport agent
  967. X# which would either call a real inews or post via nntp, as appropriate.
  968. X#
  969. X# Checks for moderators and suchlike are assumed to take place when the
  970. X# message is actually posted on the real news server.
  971. X#
  972. X# Jean-Francois Lamy (lamy@ai.toronto.edu) 88-02-11
  973. X
  974. X#NEWSCTL=${NEWSCTL-/usr/lib/news}
  975. X#NEWSBIN=${NEWSBIN-/usr/lib/newsbin}
  976. X#NEWSARTS=${NEWSARTS-/usr/spool/news}
  977. XNEWSCTL=/local/share/news
  978. XNEWSBIN=/local/lib/news
  979. XNEWSARTS=/var/spool/news
  980. XPATH=$NEWSBIN:$NEWSCTL:$NEWSBIN/relay:/bin:/usr/bin:/usr/ucb; export PATH
  981. X
  982. Xallowed=sandra\|rayan\|lamy        # tailor: local news admin (may be "")
  983. Xhdrspresent=no
  984. X
  985. Xwhoami=/tmp/cn$$who        # just created to determine effective uid
  986. Xinput=/tmp/cn$$in        # uncensored input
  987. Xcensart=/tmp/cn$$cens        # censored input
  988. Xrmlist="$input $whoami $censart"
  989. Xegrep=egrep
  990. X
  991. X# figure out where to mail the message.  We mail even if we are on the
  992. X# news server, in order to garantee proper return addresses
  993. X   servaddr=nntp
  994. X
  995. Xumask 2
  996. Xtrap '' 1 2 15            # ignore signals to avoid losing articles
  997. X
  998. X# "inews -p": invoke rnews
  999. Xcase "$1" in
  1000. X-p)
  1001. X    shift
  1002. X    exec rnews $*        # rnews, bailing out at or near line 1
  1003. X    ;;
  1004. Xesac
  1005. X
  1006. X# parse arguments for options, cat headers onto $input; cat files onto $input
  1007. X>$input
  1008. Xwhile :
  1009. Xdo
  1010. X    case $# in
  1011. X    0)    break ;;        # arguments exhausted
  1012. X    esac
  1013. X
  1014. X    case "$1" in
  1015. X    -debug)    shift; debug="$1" ;;        # peculiar to C news
  1016. X    -x)    shift; exclusion="-x $1" ;;    # you're welcome, erik (2.11)
  1017. X    -h)    hdrspresent=yes ;;
  1018. X    -M)    # TODO: what's this *really* do? dunno, find out
  1019. X        ;;
  1020. X    -D)    # obsolete, undocumented: meant "don't check for recordings".
  1021. X        # last present in B 2.10.1, invoked by readnews for followups.
  1022. X        ;;
  1023. X    -t)    shift; echo "Subject: $1" >>$input ;;
  1024. X    -n)    shift; echo "Newsgroups: $1" >>$input ;;
  1025. X    -e)    shift; echo "Expires: $1" >>$input ;;
  1026. X    -F)    # undocumented in B 2.10.1, documented in B 2.11.
  1027. X        shift; echo "References: $1" >>$input ;;
  1028. X    -d)    shift; echo "Distribution: $1" >>$input ;;
  1029. X    -a)    shift; echo "Approved: $1" >>$input ;;
  1030. X
  1031. X    # pass next options as environment variables to client.censor
  1032. X
  1033. X    -f)    shift; PASSEDFROM="$1" ;;    # complex due to Sender:
  1034. X    -o)    shift; ORGANIZATION="$1"; export ORGANIZATION ;;
  1035. X
  1036. X    -[cC])
  1037. X        # megakludge-o-rama
  1038. X        # first, permit only to super-users
  1039. X        >$whoami
  1040. X        whoever = "`ls -l $whoami | awk '{print $3}'`"
  1041. X        case $whoever in
  1042. X        root|$allowed)    : a winner ;;
  1043. X        *)
  1044. X            echo "$0: $1 restricted to super-users " >&2
  1045. X            exit 1
  1046. X            ;;
  1047. X        esac
  1048. X        rm -f $whoami
  1049. X        case "$1" in
  1050. X        -C)    cat <<! >>$input        # generate -C header
  1051. XNewsgroups: $ng
  1052. XSubject: newgroup $2
  1053. XControl: newgroup $2
  1054. XApproved: $whoever@`hostname`.`domainname`
  1055. X
  1056. Xcreated by inews -C
  1057. X!             
  1058. X            shift
  1059. X            ;;
  1060. X        -c)    cat <<! >>$input        # generate -c header
  1061. XNewsgroups: $ng
  1062. XSubject: $2
  1063. XControl: $2
  1064. XApproved: $whoever@`hostname`.`domainname`
  1065. X
  1066. Xcreated by inews -c.
  1067. X!
  1068. X            shift
  1069. X            ;;
  1070. X        esac
  1071. X        ;;
  1072. X    -*)
  1073. X        echo "$0: bad option $1" >&2
  1074. X        exit 1
  1075. X        ;;
  1076. X    *)
  1077. X        case "$hdrspresent" in
  1078. X        no)    echo "" >>$input; hdrspresent=yes ;;
  1079. X        esac
  1080. X        cat "$1" >>$input        # is a filename; append file
  1081. X        fileseen=yes
  1082. X        ;;
  1083. X    esac
  1084. X    shift        # pass option or filename (any value was done above)
  1085. Xdone
  1086. X
  1087. X# if no files named, read stdin
  1088. Xcase "$fileseen" in
  1089. Xyes)    ;;
  1090. X*)
  1091. X    case "$hdrspresent" in
  1092. X    no)    echo "" >>$input; hdrspresent=yes ;;
  1093. X    esac
  1094. X    # capture incoming news in case inews fails
  1095. X    if cat >>$input; then
  1096. X        : far out
  1097. X    else
  1098. X        echo "$0: lost news; cat returned status $?" >&2
  1099. X        exit 1
  1100. X    fi
  1101. X    ;;
  1102. Xesac
  1103. X
  1104. X(
  1105. X# trivial censoring, before passing on to mailer.
  1106. X# The Newsgroups: line is turned into a To: line.
  1107. XORGANIZATION=${ORGANIZATION=`cat ${NEWSCTL}/organi?ation`}
  1108. Xawk "BEGIN        { subject = 0; body = 0; skipping = 0 ;
  1109. X              newsgroups = 0; distribution = 0; organization = 0;
  1110. X            }
  1111. Xbody == 1        { print; next }
  1112. X/^[A-Za-z-]*:[ ]*$/    { next }
  1113. X/^$|^[ ][ \t]*$/        { if (!body) {
  1114. X                if (!organization) 
  1115. X                   print \"Organization: $ORGANIZATION\";
  1116. X                if (!newsgroups) print \"To: $groups\";
  1117. X                if (!subject) print \"Subject: (none)\"; 
  1118. X              }
  1119. X              print; body = 1; next
  1120. X            }
  1121. X/^Organization:/    { organization = 1; skipping = 0; print; next }
  1122. X/^Newsgroups:/        { \$1 = \"To:\" ; 
  1123. X              newsgroups = 1; skipping = 0; print; next }
  1124. X/^Distribution:/    { distribution = 1; skipping = 0; print; next }
  1125. X/^Subject:/        { subject = 1; skipping = 0; print; next }
  1126. X/^To:|^Cc:|^X-To:/    { skipping = 1; next }
  1127. X/^From |^Return-Path:/    { skipping = 1; next }
  1128. X/^Apparently-To:/    { skipping = 1; next }
  1129. X/^[     ]/        { if (skipping) next }
  1130. X            { print }
  1131. X" <$input >$censart
  1132. Xif test -r $HOME/.signature; then
  1133. X   echo "-- " >>$censart
  1134. X   sed 5q $HOME/.signature >>$censart    # glue on first bit of signature
  1135. Xfi
  1136. X
  1137. Xif /usr/lib/sendmail -t ${PASSEDFROM+-f"$PASSEDFROM"} <$censart
  1138. Xthen
  1139. X    rm -f $rmlist        # far out, it worked
  1140. X    exit 0
  1141. Xelse
  1142. X    status=$?
  1143. X    echo\
  1144. X"$0: could not send article to server; sendmail returned status $status" >&2
  1145. X    echo "$0: processed news article can be found in $input" >&2
  1146. X    exit $status
  1147. Xfi
  1148. X) &
  1149. !
  1150. echo 'contrib/nntpmail/mail_to_group/usenet':
  1151. sed 's/^X//' >'contrib/nntpmail/mail_to_group/usenet' <<'!'
  1152. X#!/bin/sh
  1153. X#
  1154. X# usenet newsgroup1 ... newsgroupn
  1155. X#
  1156. X# sendmail-compatible usenet transport agent.
  1157. X#                   Jean-Francois Lamy (lamy@ai.toronto.edu), 89-06-02
  1158. X#                   based on code by Rayan Zachariassen.
  1159. X#
  1160. X# The arguments are the newsgroups to which the article should be posted. A
  1161. X# complete message, including To:, From: and From_ line expected on stdin.
  1162. X# This assumes of course that the necessary magic has been done so that
  1163. X# the mailer recognizes newsgroup name and decides to use the usenet transport
  1164. X# agent on them.
  1165. X#
  1166. X# Notes:
  1167. X#
  1168. X# - this script should ultimately result in the invocation of a real
  1169. X#   "inews" that deals with moderated newsgroups and invokes relaynews.
  1170. X#   This version calls nntp, which results in calling a real inews on
  1171. X#   the news server.
  1172. X#   
  1173. X# - The news program invoked by this script should trust From: lines
  1174. X#   (otherwise workstation name hiding, full-name id generation and
  1175. X#   all other smarts done by the mailer will be lost)
  1176. X#
  1177. X# - newsgroup "postnews" is ignored, and is used so one can mail
  1178. X#   to a postnews alias a message with a Newsgroups: header, with
  1179. X#   postnews aliased to postnews@usenet, where usenet is a fake host
  1180. X#   handled by this transport agent.
  1181. X#
  1182. X# - Normally a From_ line of site!user and a From: line of user@site
  1183. X#   should be produced. If your sendmail cannot be coerced into rewriting
  1184. X#   envelope and headers differently you will need to kludge it here.
  1185. X#
  1186. X#
  1187. X# ZMailer notes:
  1188. X#
  1189. X# - The default router.cf does the appropriate things, provided that
  1190. X#   scheduler.cf contains:
  1191. X#    usenet/*    1m    10 0 0    root    daemon    sm -c $channel usenet
  1192. X#   sm.cf contains:
  1193. X#    usenet    m    /local/lib/mail/bin/usenet    usenet $u
  1194. X#      (adjust this to reflect the actual location of the installed copy of
  1195. X#       this script, of course)
  1196. X#   hosts.transport contains a line with:
  1197. X#       usenet usenet!  
  1198. X#   and that the aliases file contains aliases of the form
  1199. X#       gradnews: gradnews@usenet
  1200. X#      for all newsgroup names that don't have embedded ".").
  1201. X
  1202. X
  1203. X# this version forwards the article via NNTP
  1204. XNNTPSERVER="jarvis.csri" ; export NNTPSERVER
  1205. X# make sure this does not end up calling this script again!
  1206. Xinews=/local/lib/news/nntp_inews
  1207. X
  1208. Xorgflag=0
  1209. Xorg="`cat /local/share/news/organi?ation`"
  1210. X[ "$org" ] || orgflag=1  # do not print empty Organization: header
  1211. X
  1212. Xfrom=/tmp/from$$
  1213. X
  1214. Xfor i in $@
  1215. Xdo
  1216. X    groups="${groups+$groups,}$i"
  1217. Xdone
  1218. X
  1219. Xawk "BEGIN        { subject = 0; body = 0; skipping = 0 ;
  1220. X              newsgroups = 0; distribution = 0;
  1221. X              organization = $orgflag; }
  1222. Xbody == 1        { print; next }
  1223. X/^$|^[ ][ \\t]*$/    { if (!body) {
  1224. X                np = split(path,parts,\"!\");
  1225. X                if (!organization && np == 1)
  1226. X                    print \"Organization: $org\";
  1227. X                if (!newsgroups) print \"Newsgroups: $groups\";
  1228. X                if (!subject) print \"Subject: (none)\"; 
  1229. X              }
  1230. X              print; body = 1; next
  1231. X            }
  1232. X/^To:|^X-To:|^Cc:|^Apparently-To:/    { skipping=1 ; next }
  1233. X/^Received:/        { skipping = 1; next }
  1234. X/^Newsgroups:/        { newsgroups = 1; skipping = 0; printf(\"%s\",\$0);
  1235. X                if (\"$groups\" != \"\" && \"$groups\" != \"postnews\")
  1236. X                 printf(\",%s\\n\",\"$groups\");
  1237. X              else printf(\"\\n\");
  1238. X              next }
  1239. X/^Organi[sz]ation:/    { organization = 1; skipping = 0; print; next }
  1240. X/^Distribution:/    { distribution = 1; skipping = 0; print; next }
  1241. X/^Subject:/        { subject = 1; skipping = 0; print; next }
  1242. X/^From |^Return-Path:/    { print \$2 > from ; path = \$2 ; skipping = 1; next }
  1243. X/^[     ]/        { if (skipping) next }
  1244. X/^[A-Za-z-]*:[ \\t]*$/    { if (!body) next }
  1245. X            { print }
  1246. X" from="$from" - >/tmp/usenet.$$-1
  1247. X
  1248. Xif [ -s $from ]; then
  1249. X   (echo -n "Path: "; cat $from ; cat /tmp/usenet.$$-1 ) > /tmp/usenet.$$-2
  1250. X   $inews /tmp/usenet.$$-2
  1251. Xfi
  1252. Xrm $from /tmp/usenet.$$-*
  1253. Xexit 0
  1254. !
  1255. echo 'contrib/rn.mod/cdiff.addng.c':
  1256. sed 's/^X//' >'contrib/rn.mod/cdiff.addng.c' <<'!'
  1257. X*** addng.old.c    Sat Jun  3 05:56:19 1989
  1258. X--- addng.c    Sat Jun  3 05:56:20 1989
  1259. X***************
  1260. X*** 1,4
  1261. X! /* $Header: addng.c,v 1.1 89/06/03 05:29:01 geoff Exp $
  1262. X   *
  1263. X   *    UW Mods:
  1264. X   *        GETNG_YNQ - typing Q gets you out of the newsgroup loop
  1265. X
  1266. X--- 1,4 -----
  1267. X! /* $Header: addng.c,v 1.2 89/06/03 05:35:30 geoff Exp $
  1268. X   *
  1269. X   *    UW Mods:
  1270. X   *        GETNG_YNQ - typing Q gets you out of the newsgroup loop
  1271. X***************
  1272. X*** 3,10
  1273. X   *    UW Mods:
  1274. X   *        GETNG_YNQ - typing Q gets you out of the newsgroup loop
  1275. X   * $Log:    addng.c,v $
  1276. X!  * Revision 1.1  89/06/03  05:29:01  geoff
  1277. X!  * Initial revision
  1278. X   * 
  1279. X   * Revision 1.3  87/09/10  19:39:47  sahayman
  1280. X   * newlist for SERVER now asks for all groups from the dawn of time
  1281. X
  1282. X--- 3,10 -----
  1283. X   *    UW Mods:
  1284. X   *        GETNG_YNQ - typing Q gets you out of the newsgroup loop
  1285. X   * $Log:    addng.c,v $
  1286. X!  * Revision 1.2  89/06/03  05:35:30  geoff
  1287. X!  * nuke a useless stat.
  1288. X   * 
  1289. X   * Revision 1.3  87/09/10  19:39:47  sahayman
  1290. X   * newlist for SERVER now asks for all groups from the dawn of time
  1291. X***************
  1292. X*** 183,189
  1293. X  char *ngnam;
  1294. X  ART_NUM ngsize;
  1295. X  {
  1296. X-     char tst[128];
  1297. X      long time();
  1298. X   
  1299. X      sprintf(tst, ngsize ? "%s/%s/1" : "%s/%s" ,spool,getngdir(ngnam));
  1300. X
  1301. X--- 183,188 -----
  1302. X  char *ngnam;
  1303. X  ART_NUM ngsize;
  1304. X  {
  1305. X      long time();
  1306. X   
  1307. X      /*
  1308. X***************
  1309. X*** 186,192
  1310. X      char tst[128];
  1311. X      long time();
  1312. X   
  1313. X-     sprintf(tst, ngsize ? "%s/%s/1" : "%s/%s" ,spool,getngdir(ngnam));
  1314. X      /*
  1315. X       * After a long oddyssey of changes, we have
  1316. X       * restored the patch 19 behaviour here.
  1317. X
  1318. X--- 185,190 -----
  1319. X  {
  1320. X      long time();
  1321. X   
  1322. X      /*
  1323. X       * After a long oddyssey of changes, we have
  1324. X       * restored the patch 19 behaviour here.
  1325. X***************
  1326. X*** 192,197
  1327. X       * restored the patch 19 behaviour here.
  1328. X       * This gives the minimum number of wrong answers.
  1329. X       * ..sah 87/07/29
  1330. X       */
  1331. X  
  1332. X      if (stat(tst,&filestat) < 0)
  1333. X
  1334. X--- 190,197 -----
  1335. X       * restored the patch 19 behaviour here.
  1336. X       * This gives the minimum number of wrong answers.
  1337. X       * ..sah 87/07/29
  1338. X+      * Bzzt!  Wrong!  Article 1 will always be long gone; nuke da stat(2).
  1339. X+      * - geoff
  1340. X       */
  1341. X      /* not there, assume something good */
  1342. X      return (ngsize ? 0L : time(Null(long *)));
  1343. X***************
  1344. X*** 193,204
  1345. X       * This gives the minimum number of wrong answers.
  1346. X       * ..sah 87/07/29
  1347. X       */
  1348. X! 
  1349. X!     if (stat(tst,&filestat) < 0)
  1350. X!     return (ngsize ? 0L : time(Null(long *)));
  1351. X!     /* not there, assume something good */
  1352. X!     else
  1353. X!     return filestat.st_mtime;
  1354. X  }
  1355. X  
  1356. X  bool
  1357. X
  1358. X--- 193,200 -----
  1359. X       * Bzzt!  Wrong!  Article 1 will always be long gone; nuke da stat(2).
  1360. X       * - geoff
  1361. X       */
  1362. X!     /* not there, assume something good */
  1363. X!     return (ngsize ? 0L : time(Null(long *)));
  1364. X  }
  1365. X  
  1366. X  bool
  1367. X
  1368. X
  1369. X
  1370. !
  1371. echo 'contrib/rn.mod/README':
  1372. sed 's/^X//' >'contrib/rn.mod/README' <<'!'
  1373. XThe cdiff.* files contain a pair of rn speedups, relative to rn
  1374. Xpatchlevel 40 as modified by U of Waterloo: they remove some expensive
  1375. Xstat system calls.  The base U of Waterloo rn contains two other handy
  1376. Xchanges:  a -q which disables the interrogation when the active file
  1377. Xchanges, and a third answer during the interrogation: "q" means "I
  1378. Xdon't care, just show me some news, right now".
  1379. X
  1380. XThe changes to ngdata.c prevent rn stating every file under
  1381. X/usr/spool/news that might contain an article before opening it.
  1382. X
  1383. XThe changes to addng.c prevent rn stating all ~700 directories under
  1384. X/usr/spool/news every time the active file changes (this is known as
  1385. X"the rn huddle").  In the one timing trial we did, this reduced start
  1386. Xup time after touching active from 56 seconds elapsed on a Sun 3 to 8
  1387. Xseconds.  Before making these changes, longer huddles in the range of
  1388. X10 to 15 minutes were observed on Sun 3s and 4s, perhaps because the
  1389. Xactive file was touched in a different spot.
  1390. X
  1391. XUnfortunately the new addng.c code means that you will get an even
  1392. Xlonger interrogation after the shorter huddle than you previously
  1393. Xwould, as many groups will be spuriously considered "new".  If you have
  1394. X-q available, you can keep up with new groups by just reading the
  1395. X"control" pseudo-group with "ihave", "sendme" and "cancel" in your
  1396. Xcontrol kill file.
  1397. X
  1398. XThe theory behind the 700 stats in the newgroup huddle was apparently
  1399. Xthat if rn stats group/1, and it exists, then group must be a
  1400. Xnewly-created group.  There's gotta be a better way.  With rapid
  1401. Xexpiry, group/1 won't be around for long in most groups, causing rn to
  1402. Xmiss some new groups, and in "valuable" groups with long expiry times,
  1403. Xgroup/1 will be around for a very long time, making rn spuriously think
  1404. Xthat the old groups are new.  Proper fixes for this problem involve
  1405. Xreworking rn's strategy for determining new newsgroups completely,
  1406. Xusing the "active.times" file.  The file "better.way" is an attempt
  1407. Xto do exactly that.
  1408. !
  1409. echo 'contrib/rn.mod/cdiff.ngdata.c':
  1410. sed 's/^X//' >'contrib/rn.mod/cdiff.ngdata.c' <<'!'
  1411. X*** ngdata.old.c    Sat Jun  3 05:56:22 1989
  1412. X--- ngdata.c    Sat Jun  3 05:56:22 1989
  1413. X***************
  1414. X*** 1,4
  1415. X! /* $Header: ngdata.c,v 1.1 89/06/03 05:44:45 geoff Exp $
  1416. X   *
  1417. X   * Modified to work with NNTP server.  -- Phil Lapsley
  1418. X   * $Log:    ngdata.c,v $
  1419. X
  1420. X--- 1,4 -----
  1421. X! /* $Header: ngdata.c,v 1.2 89/06/03 05:55:42 geoff Exp $
  1422. X   *
  1423. X   * Modified to work with NNTP server.  -- Phil Lapsley
  1424. X   * $Log:    ngdata.c,v $
  1425. X***************
  1426. X*** 2,9
  1427. X   *
  1428. X   * Modified to work with NNTP server.  -- Phil Lapsley
  1429. X   * $Log:    ngdata.c,v $
  1430. X!  * Revision 1.1  89/06/03  05:44:45  geoff
  1431. X!  * Initial revision
  1432. X   * 
  1433. X   * Revision 1.2  87/07/29  14:28:38  sahayman
  1434. X   * SERVER changes merged in
  1435. X
  1436. X--- 2,9 -----
  1437. X   *
  1438. X   * Modified to work with NNTP server.  -- Phil Lapsley
  1439. X   * $Log:    ngdata.c,v $
  1440. X!  * Revision 1.2  89/06/03  05:55:42  geoff
  1441. X!  * nuke da stats
  1442. X   * 
  1443. X   * Revision 1.2  87/07/29  14:28:38  sahayman
  1444. X   * SERVER changes merged in
  1445. X***************
  1446. X*** 240,246
  1447. X      register ART_NUM min = 1000000;
  1448. X      register ART_NUM maybe;
  1449. X      register char *p;
  1450. X-     char tmpbuf[128];
  1451. X      
  1452. X      dirp = opendir(dirname);
  1453. X      if (!dirp)
  1454. X
  1455. X--- 240,245 -----
  1456. X      register ART_NUM min = 1000000;
  1457. X      register ART_NUM maybe;
  1458. X      register char *p;
  1459. X      
  1460. X      dirp = opendir(dirname);
  1461. X      if (!dirp)
  1462. X***************
  1463. X*** 250,263
  1464. X          for (p = dp->d_name; *p; p++)
  1465. X          if (!isdigit(*p))
  1466. X              goto nope;
  1467. X!         if (*dirname == '.' && !dirname[1])
  1468. X!         stat(dp->d_name, &filestat);
  1469. X!         else {
  1470. X!         sprintf(tmpbuf,"%s/%s",dirname,dp->d_name);
  1471. X!         stat(tmpbuf, &filestat);
  1472. X!         }
  1473. X!         if (! (filestat.st_mode & S_IFDIR))
  1474. X!         min = maybe;
  1475. X      }
  1476. X        nope:
  1477. X      ;
  1478. X
  1479. X--- 249,264 -----
  1480. X          for (p = dp->d_name; *p; p++)
  1481. X          if (!isdigit(*p))
  1482. X              goto nope;
  1483. X!         /*
  1484. X!          * dp->d_name is all-numeric.  anyone dopey enough to create
  1485. X!          * an all-numeric component of a newsgroup name should be chopped
  1486. X!          * into tiny bits and the bits should be jumped on.  even given
  1487. X!          * such dopes, rn should not attempt to read a directory later on,
  1488. X!          * and it wouldn't be the end of the world if it did anyway.
  1489. X!          * so i'll take the miniscule risk in return for getting to
  1490. X!          * NUKE DA stat(2)s! - geoff
  1491. X!          */
  1492. X!         min = maybe;
  1493. X      }
  1494. X        nope:
  1495. X      ;
  1496. X***************
  1497. X*** 265,268
  1498. X      closedir(dirp);
  1499. X      return min==1000000 ? 0 : min;
  1500. X  }
  1501. X- 
  1502. X
  1503. X--- 266,268 -----
  1504. X      closedir(dirp);
  1505. X      return min==1000000 ? 0 : min;
  1506. X  }
  1507. X
  1508. !
  1509. echo done
  1510.  
  1511.  
  1512.